@extends('admin.layout')
@section('title',$title)
@section('content')
     <meta name="_token" content="{{ csrf_token() }}"/>
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                订单详情
                
            </h1>
            <ol class="breadcrumb">
                <li><a href="/admin/order/index"><i class="fa fa-dashboard"></i>订单列表 </a></li>
                <li class="active">

                </li>
            </ol>
        </section>
        <!-- 用户添加成功 -->
        @if (session('success'))
            <div class="alert alert-success alert-dismissable">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                <h4><i class="icon fa fa-check"></i>恭喜!</h4>
                        {{ session('success') }}
            </div>
        @endif
<!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            {{--分页--}}
                           
                        </div><!-- /.box-header -->
                        <!-- 订单详情 -->
                        <div class="box-body">
                            <table id="example2" class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>商品ID</th>
                                    <th>商品名</th>
                                    <th>商品图片</th>
                                    <th>商品价格</th>
                                    <th>购买数量</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $indent)
                                <tr>
                                    <td>{{$indent -> goods_id}}</td>
                                    <td>{{$indent -> goodsname}}</td>
                                    <td><img src="{{$indent -> goods_pic}}" width="100"></td>
                                    <td>{{$indent -> price}}</td>
                                    <td>{{$indent -> num}}</td>
                                    <!-- 商品是否发货 -->
                                    <td id="did">
                                    @if($indent -> status == 0)
                                        <p class="btn btn-block btn-info status" data-value="{{$indent -> id}}">点击发货</p>
                                    @else
                                        <samll class="btn btn-block btn-success">已发货</samll>
                                    @endif
    
                                    </td>
                                    <!-- 编辑和删除 -->
                                    <td>
                                    <a href="/admin/order/delete/{{$indent -> id}}" class="btn btn-block btn-danger">删除</a>
                                    </td>
                                </tr>
                                @endforeach
                                </tfoot>
                            </table>
                           <script type="text/javascript">

                           // alert($);
                            $.ajaxSetup({
                                            headers: {
                                                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                                            }
                                        });

                            $('.status').on('click',function(){
                                var id = $(this).attr('data-value');
                                // console.log(id);
                                //获取元素的父元素
                                var td = $(this).parent();


                                $.ajax({
                                    type:'post',
                                    url:"{{asset('/admin/order/status')}}",
                                    data:{'id':id},
                                                                            
                                    success:function(data)
                                    {  
                                     // console.log(data);
                                     // alert(111);
                                        if(data)
                                        {
                                            td.empty();//清空当前点击的父元素

                                            var p = '<small class="btn btn-block btn-success">已发货</small>';
                                            td.append(p);
                                        }
                                                                      

                                    },
                                    dataType:'json'
                                });
                                // alert(111);
                            });
                         
                           </script>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
@endsection
